import { ref } from 'vue';
import api from 'axios';
import { cataItem } from 'src/hook/common/useCatalogType';
import { cinCatalogType, cinCatalogUrlAPI } from 'src/util/CinBaseConst';


export function useCinCatalogTbl () {
  const cinProjectList = ref<cataItem[]>([]);//项目列表
  const cinPageList = ref<cataItem[]>([]);//页面列表

  //路径
  let url = ref('');

  //从后台读取目录
  const getCinCatalog = (catalog: cinCatalogType) => {
    switch (catalog) {
      case cinCatalogType.PROJECT_CODE:
        url.value = cinCatalogUrlAPI.PROJECT_API;
        api.post(url.value).then((res) => {
          cinProjectList.value = res.data.data;
        })
        break;
      default:
        break;
    }
  };


  //释放目录
  const removeCinCatalog = (catalog: cinCatalogType) => {
    switch (catalog) {
      case cinCatalogType.PROJECT_CODE:
        cinProjectList.value.length = 0;
        break;
      case cinCatalogType.PAGE_CODE:
        cinPageList.value.length = 0;
        break;
      default:
        break;
    }
  }
  return {
    cinProjectList,
    cinPageList,

    getCinCatalog,
    removeCinCatalog
  }
}
